﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="other.aspx.cs" Inherits="Guide.other" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:CheckBox ID="CheckBox2" runat="server" />
        <asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList>
    </div>
    </form>
</body>
</html>
1 using System; 2 using System.Data; 3 using System.Configuration; 4 using System.Collections;
5 using System.Web; 6 using System.Web.Security; 7 using System.Web.UI; 8 using
System.Web.UI.WebControls; 9 using System.Web.UI.WebControls.WebParts; 10 using
System.Web.UI.HtmlControls; 11 12 public partial class Demo44 : System.Web.UI.Page
13 { 14 protected void Page_Load(object sender, EventArgs e) 15 { 16 if (Page.IsPostBack
== false) 17 { 18 BindData(); 19 } 20 } 21 22 public void BindData() 23 { 24 string
strSql = "select UserID,C_Name,E_name,UpdataDate,salary,QQ,Zip_Code,isdy from Demo_User
"; 25 DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.CONN_STRING, CommandType.Text,
strSql, null).Tables[0]; 26 27 GridView.DataSource = dt; 28 GridView.DataKeyNames
= new string[] { "UserID" };//主键 29 GridView.DataBind(); 30 } 31 32 protected void
GridView_PageIndexChanging(object sender, GridViewPageEventArgs e) 33 { 34 GridView.PageIndex
= e.NewPageIndex; 35 BindData(); 36 } 37 } 1
<table align="center" bgcolor="#c0de98" border="0" cellpadding="0" cellspacing="1"
    width="99%">
    2
    <tr>
        3
        <th colspan="2">
            4 GridView演示
        </th>
        5
    </tr>
    6
    <tr>
        7
        <td colspan="2" style="width: 100%;">
            8
            <asp:gridview id="GridView" runat="server" width="100%" autogeneratecolumns="False"
                allowpaging="True" onpageindexchanging="GridView_PageIndexChanging" pagesize="12">
 9                 <Columns>
10                       <asp:BoundField DataField="UserID" HeaderText="UserID" />            
11                       <asp:BoundField DataField="C_Name" HeaderText="中文名字"  />
12                       <asp:BoundField DataField="E_Name" HeaderText="英文名字"  /> 
13                       <asp:BoundField DataField="salary" HeaderText="薪水" DataFormatString="{0:C}"  HtmlEncode ="False"/> 
14                       <asp:BoundField DataField="QQ" HeaderText="QQ"  />   
15                       <asp:BoundField DataField="Zip_Code" HeaderText="邮政编码"  />   
16                       <asp:TemplateField HeaderText="是否党员" SortExpression="Isdy">
17                         <ItemTemplate>
18                             <asp:CheckBox ID="CheckBox1"  runat="server" Checked='<%#DataBinder.Eval(Container.DataItem,"Isdy") == DBNull.Value?false:Convert.ToBoolean(Eval("Isdy"))%>' />
19                         </ItemTemplate>
20                     </asp:TemplateField>           
21                   </Columns>
22                   <RowStyle HorizontalAlign="Center" /> 
23                   <PagerStyle HorizontalAlign="Center" />                 
24               </asp:gridview>
            25
        </td>
        26
    </tr>
    27 28
</table>
